package com.info.dpunified.web.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.info.dpunified.defects.DefectsSubmissionStatusSelector;

public class DefectSubmissionStatusReportServlet extends HttpServlet{

	/**
	 * 
	 */
	private static final long serialVersionUID = 4816259529968282411L;

	public void doGet(HttpServletRequest request,  
            HttpServletResponse response) throws IOException,  
                                                 ServletException {  
		doPost(request, response);  
	}  

	public void doPost(HttpServletRequest request,HttpServletResponse response)
	throws ServletException, IOException
	{
	
		String year = request.getParameter("selectYear");
		
		DefectsSubmissionStatusSelector defectsSubmissionStatusSelector = new DefectsSubmissionStatusSelector();
		
		HashMap<String, ArrayList<String>> defectStatusMap = defectsSubmissionStatusSelector.fetchSubmittedDefects(year);
	
		request.setAttribute("months", defectsSubmissionStatusSelector.fetchMonthsList());
		request.setAttribute("statusMap", defectStatusMap);
		
		
		try {
			getServletConfig().getServletContext().getRequestDispatcher("/jsp/defectsubmissionstatusreport.jsp").forward(request, response);
		} catch (ServletException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
